<?php

Yii::import('application.extensions.phpmailer.PHPMailer');
class SendMail extends PHPMailer {

    public function sendGmailAlertContact($body) {

//        //$this->Username = Yii::app()->params['adminEmail'];
//        //$this->Password = Yii::app()->params['adminEmailPassword'];
//        $this->SetFrom('arnon.ph@gmail.com', 'Thai Escrow');
//        //$this->SetFrom(Yii::app()->params['adminEmail'], Yii::app()->params['adminEmailName']);
        $emailconfig = Common::getOptionValue('contactemail');
        $mail = new PHPMailer();
        $mail->IsHTML(true); // กำหนดให้ ส่งเป็น html
        $mail->IsSMTP();
        $mail->SMTPAuth = true; // enable SMTP authentication
        $mail->Host = 'ssl://smtp.gmail.com:465'; // รวมเป็น ตัวแปลเดียวแบบนี้ก็ได้
        $mail->Username = $emailconfig['email'];
        $mail->Password = $emailconfig['password'];
        //$mail->From = "root@localhost"; // "name@yourdomain.com";
        $mail->FromName = $emailconfig['formname'];
        $mail->Subject = $emailconfig['subject'];
        $mail->Body = $body;            // attachment
        $mail->AddAddress($emailconfig['receiver']);
        if (!$mail->Send()) {// ส่งเมลออก 
            return "Mailer Error: " . $mail->ErrorInfo;
        } else {
            return "Message sent!";
        }
    }
    public function sendGmailReply($subject, $body, $email) {

//        //$this->Username = Yii::app()->params['adminEmail'];
//        //$this->Password = Yii::app()->params['adminEmailPassword'];
//        $this->SetFrom('arnon.ph@gmail.com', 'Thai Escrow');
//        //$this->SetFrom(Yii::app()->params['adminEmail'], Yii::app()->params['adminEmailName']);
        $emailconfig = Common::getOptionValue('contactemail');
        $mail = new PHPMailer();
        $mail->IsHTML(true); // กำหนดให้ ส่งเป็น html
        $mail->IsSMTP();
        $mail->SMTPAuth = true; // enable SMTP authentication
        $mail->Host = 'ssl://smtp.gmail.com:465'; // รวมเป็น ตัวแปลเดียวแบบนี้ก็ได้
        $mail->Username = $emailconfig['email'];
        $mail->Password = $emailconfig['password'];
        //$mail->From = "root@localhost"; // "name@yourdomain.com";
        $mail->FromName = $emailconfig['formname'];
        $mail->Subject = $subject;
        $mail->Body = $body;            // attachment
        $mail->AddAddress($email);
        if (!$mail->Send()) {// ส่งเมลออก 
            return "Mailer Error: " . $mail->ErrorInfo;
        } else {
            return "Message sent!";
        }
    }

}

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
?>
